<template>
  <div>
    <el-tooltip class="item" effect="dark" content="全屏" placement="bottom">
      <svg-icon v-if="flag" icon-class="fullscreen" class="icon" @click="toggle" />
      <svg-icon v-else icon-class="exit-fullscreen" class="icon" @click="toggle" />
    </el-tooltip>
  </div>
</template>

<script>
import screenFull from 'screenfull' // yarn add screenfull@5.2.0
export default {
  data() {
    return {
      flag: true
    }
  },
  methods: {
    toggle() {
      console.log(screenFull.isEnabled) // 检测浏览器是否支持全屏
      if (screenFull.isEnabled) {
        // 是全屏状态就退出全屏, 不是全屏状态就开启全屏
        screenFull.toggle()
        this.flag = !this.flag
      } else {
        this.$message.warning('您的浏览器不支持全屏')
      }
    }
  }
}
</script>

<style scoped lang="scss">
.icon {
  fill: white;
  cursor: pointer;
}
</style>
